namespace Collaboris.Saf.Actions.Wss.Tests.Generated
{
    using System;

    using Engine.Report;

    using Microsoft.SharePoint;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Saf.Tests;
    using Entities;

    using SharePoint.Wss.Lists;

    using Wss.List;

    using TestHelper=Collaboris.Saf.Actions.Wss.Tests.TestHelper;

    /// <summary>
    /// This test was originally generated but has now been tested and verfiied by MJ
    /// </summary>
    [TestClass]
    public class DeleteListTest
    {
        [TestMethod]
        public void Recycle_List_Test()
        {
            WSSTestAssistant<DeleteList, ListToDelete> deletelist =
                    new WSSTestAssistant<DeleteList, ListToDelete>(TestEnvironment.PublishingSite, 
                        "DeleteListTestWeb", "BLANKINTERNET#0");

            using (deletelist)
            {
                TestHelper.CreatePersonList(deletelist.TestWeb, true, true);
                MacroReport doReport = deletelist.DoMacro();

                Assert.IsNull(SPListHelper.GetList(deletelist.TestWeb, "PersonList", false));
                
                MacroReport unDoReport = deletelist.UndoMacro();

                // We have to put this line in as the restored list will NOT refresh on the current web. (I think it a caching bug)
                // this line really has no bearing to the current unit test other than it forces a refresh of the list collection.
                deletelist.TestWeb.Lists.ListsForCurrentUser = !deletelist.TestWeb.Lists.ListsForCurrentUser;
                
                Assert.IsNotNull(SPListHelper.GetList(deletelist.TestWeb, "PersonList", false, false));
            }
        }

        /// <summary>
        /// Tests that a List is completely NOT deleted and placed into the 
        /// Recycle Bin.
        /// </summary>
        [TestMethod]
        public void Delete_List_Test()
        {
            WSSTestAssistant<DeleteList, ListToDelete> deletelist =
                    new WSSTestAssistant<DeleteList, ListToDelete>(TestEnvironment.PublishingSite,
                        "DeleteListTestWeb", "BLANKINTERNET#0");

            using (deletelist)
            {
                TestHelper.CreatePersonList(deletelist.TestWeb, true, true);
                deletelist.FirstEntity.Destroy = true;
                SPList list = SPListHelper.GetList(deletelist.TestWeb, "PersonList", false);
                Guid listGuid = list.ID;

                MacroReport doReport = deletelist.DoMacro();
                
                Assert.IsNull(SPListHelper.GetList(deletelist.TestWeb, "PersonList", false));

                MacroReport unDoReport = deletelist.UndoMacro();

                // We have to put this line in as the restored list will NOT refresh on the current web. (I think it a caching bug)
                // this line really has no bearing to the current unit test other than it forces a refresh of the list collection.
                deletelist.TestWeb.Lists.ListsForCurrentUser = !deletelist.TestWeb.Lists.ListsForCurrentUser;

                Assert.IsFalse(SPListHelper.ListInRecycleBin(deletelist.TestWeb, listGuid));
            }
        }


    }
}
